<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<!--[if IE 8]>
<html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en"> <!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <meta charset="utf-8"/>
    <title>Bone</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
    <!-- BEGIN GLOBAL MANDATORY STYLES -->
    <%@ include file="/common/css.jsp"%>
    <!-- END GLOBAL MANDATORY STYLES -->
    <link href="${ctx}/resource/css/promo.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/resource/css/animate.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript">
    //分页查询调用
    function pageSelect(ob){
       var nowPage=parseInt($("#nowPage").val());
       var lastPage=parseInt($("#totalPage").val());
       var currentPage=nowPage;
       var id=$(ob).attr("id");
       if(id=="firstbt"){
         $("#nowPage").val("1");
         $("#listForm").submit();
       }
       else if(id=="prevbt"){
          currentPage=currentPage-1;
          if(currentPage==1){
             $("#prevbt").attr("disabled", true);
          }
          $("#nowPage").val(currentPage);
          $("#currentpage").html(currentPage);
           $("#listForm").submit();
       
       }else if(id=="nextbt"){
          currentPage=currentPage+1;
        /**  alert("nextbt_curpage="+currentPage);
          alert("nextbt_lastPage="+lastPage);
          */
          if(currentPage>=lastPage){
            $("#nextbt").attr("disabled", true);
          }
          $("#nowPage").val(currentPage);
          $("#currentpage").html(currentPage);
           $("#listForm").submit();
       
       }else{
          currentPage=lastPage;
          $("#nowPage").val(currentPage);
          $("#currentpage").html(currentPage);
           $("#listForm").submit();
       }
      
    }
    //下拉框查询调用
    function searchSelectOper(){
      $("#listForm").submit();
    }
    //搜索框搜索调用
    function titleSearch(){
      var title_search=$("#title_search").val();
      $("#title_search").val($.trim(title_search));
       $("#listForm").attr("action","${ctx}/vote/list.do");
       $("#listForm").submit();
    }
    //删除投票话题操作
    function deleteVoteData(param){
      var tid=param;
        $.ajax({     
        type:'post',        
        url:'${ctx}/vote/delete.do?tid='+tid,   
       // data:formParam,     
        cache:false,     
        dataType:'json',     
        success:function(data){      
        	layer.msg(data.message);  
              if(data.code==0000){
               $("#listForm").submit();
              }                       
        }
    }); 
    }

    function updateVote(param){
        var tid=param;
          $.ajax({     
          type:'post',        
          url:'${ctx}/vote/checkUpdate.do?tid='+tid,   
          cache:false,     
          dataType:'json',     
          success:function(data){
                if(data.flag == "success"){
                    window.location.href="${ctx}/vote/updateVotePage.do?tid="+tid;
                } else {
                	layer.msg(data.message);
                }
          }
      }); 
      }
</script>
    
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="page-header-fixed page-full-width">
<!-- BEGIN HEADER -->
<%@ include file="/common/header.jsp"%>
<!-- END HEADER -->

<!--content start-->
<div class="tab-pane row-fluid profile-account" id="tab_1_3" style="margin-top:40px">

    <div class="row-fluid">
        <div class="span2"></div>
        <div class="span8">
            <h3 class="page-title">
                投票列表
            </h3>
            <ul class="breadcrumb">
                <li>
                    <i class="icon-home"></i>
                    <a href="${ctx}/vote/index.do">首页</a>
                    <i class="icon-angle-right"></i>
                </li>
                <li><a href="#">投票列表</a></li>
            </ul>
        </div>
    </div>
    <div class="row-fluid">

        <div class="span2"></div>
        <div class="span8" style="min-height:600px">
            <!-- BEGIN EXAMPLE TABLE PORTLET-->
            <div class="portlet box blue">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-edit"></i>投票列表</div>
                </div>
             <form id="listForm" action="${ctx}/vote/list.do" method="post">
                <div class="portlet-body">
                    <div id="sample_editable_1_wrapper" class="dataTables_wrapper form-inline" role="grid">
                        <div class="row-fluid">
                            <div class="span7">
                            <c:choose>
					<c:when test="${!empty LOGINED_USER.uid}">
						<div style="width:10%; float:left; ">
							<label style="left: 20px;"> <select id="select_search"
								onchange="searchSelectOper()" name="select_search" class="medium m-wrap" tabindex="1">
									<option label="" value="2" <c:if test="${'2' eq dataMap.select_search}">selected</c:if> >----全部----</option>
									<option label="" value="0" <c:if test="${'0' eq dataMap.select_search}">selected</c:if> >我发起的投票</option>
									<option label="" value="1" <c:if test="${'1' eq dataMap.select_search}">selected</c:if>>我参与的投票</option>
							</select> </label>
						</div>

					</c:when>
				</c:choose>
                            </div>
                            <div class="span5 controls">
                                <div class="dataTables_filter pull-right" id="sample_editable_1_filter">
                                <label style="right: 30px;"><input id="title_search" class="m-wrap" style="padding: 5px 5px;" name="title_search" value="<vs:escape value='${dataMap.title_search}' input='true'/>"  /> 
                                <input type="button" class="m-wrap" id="title_search" onclick="titleSearch();" style="padding: 5px 5px;" value="搜   索"></label>
                                </div>
                            </div>
                        </div>
                        <table class="table table-striped table-hover table-bordered dataTable" id="sample_editable_1"
                               aria-describedby="sample_editable_1_info" style="width: px;">
                            <thead>
                            <tr role="row">
                                <th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1"
                                    style="width: 80px;" aria-label="Username">序号
                                </th>
                                <th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_editable_1"
                                    rowspan="1" colspan="1" style="width: 370px;"
                                    aria-label="Full Name: activate to sort column ascending">标题
                                </th>
                                <th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_editable_1"
                                    rowspan="1" colspan="1" style="width: 155px;"
                                    aria-label="Points: activate to sort column ascending">投票类型
                                </th>
                                <th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_editable_1"
                                    rowspan="1" colspan="1" style="width: 155px;"
                                    aria-label="Notes: activate to sort column ascending">投票发起人
                                </th>
                                 <th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_editable_1"
                                    rowspan="1" colspan="1" style="width: 300px;"
                                    aria-label="Notes: activate to sort column ascending" >投票截止时间
                                </th>
                                 <th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_editable_1"
                                    rowspan="1" colspan="1" style="width: 300px;"
                                    aria-label="Notes: activate to sort column ascending">投票发布时间
                                </th>
                               
                                  <c:if test="${!empty sessionScope.LOGINED_USER.uid}">
                                    <c:if test="${'0' eq dataMap.select_search}">
                                      <th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_editable_1"
                                    rowspan="1" colspan="1" style="width: 116px;"
                                    aria-label="Edit: activate to sort column ascending">修 改
                                      </th>
                                    </c:if>
                                  
                                </c:if> 
                                 <c:if test="${!empty sessionScope.LOGINED_USER.uid}">
                                    <c:if test="${'0' eq dataMap.select_search}">
                                  <th class="sorting_desc" role="columnheader" tabindex="0"
                                    aria-controls="sample_editable_1" rowspan="1" colspan="1" style="width: 157px;"
                                    aria-sort="descending" aria-label="Delete: activate to sort column ascending">删 除
                                </th>   
                                 </c:if>                            
                                 </c:if>
                               
                            </tr>
                            </thead>
                            <tbody role="alert" aria-live="polite" aria-relevant="all">
                              <c:forEach items="${dataMap.dataList}" var="obj"
							varStatus="status">
							<tr class="gradeX">
							<!-- 
							<td class="aligncenter"><span class="center"> <input id="checkItem"
										type="checkbox" value="${obj.tid}" name="checkItem"/> </span>
								</td>
							 -->
								
								<td>${status.index+1}</td>
								<td><a href="${ctx}/vote/router/route.do?topicId=${obj.tid}"  >${obj.title}</a></td>
								<td>
								    <c:if test="${'0' eq obj.type}">单选项</c:if>
								    <c:if test="${'1' eq obj.type}">多选项</c:if>
								</td>
								<td>${obj.name}</td>
								<td>${obj.deadline}</td>
								<td>${obj.create_time}</td>
								<c:if test="${!empty sessionScope.LOGINED_USER.uid}">
								   <c:if test="${'0' eq dataMap.select_search}">
								<td class=" "><a class="edit" href="#" onclick="updateVote('${obj.tid}')">Edit</a> </td>
								   </c:if>
								</c:if> 
								    
								
                                <c:if test="${!empty sessionScope.LOGINED_USER.uid}">
                                  <c:if test="${'0' eq dataMap.select_search}">
                                <td class="sorting_1"><a class="delete" href="#" onclick="deleteVoteData('${obj.tid}')">Delete</a></td>
                                  </c:if>
                                </c:if>
                                                    
                                
                                
							</tr>
						     </c:forEach>
                            </tbody>
                        </table>	
								<div hidden="ture" style="display: none">
									<input id="uid" name="uid"
										value="${sessionScope.LOGINED_USER.uid}"> <input
										id="nowPage" name="nowPage" value="${dataMap.nowPage}" /> <input
										id="totalRecord" name="totalRecord"
										value="${dataMap.totalRecord}"> <input id="totalPage"
										name="totalPage" value="${dataMap.totalPage}" />
								</div>

								<div class="row-fluid">
                            <div class="span4">
                                              &nbsp;<font color="gray"> 共有<span><font size="5" color="black">${dataMap.totalRecord}</font></span>条数据,共计<span><font size="5" color="black">${dataMap.totalPage}</font></span>页</font>
                            </div>
                            <div class="span8">
                                <div class="dataTables_paginate paging_bootstrap pagination pull-right" >
                <c:if test="${dataMap.totalPage>1}">
                                    <ul>
                                        
                                        <li class="prev"><a href="#" id="firstbt" onclick="pageSelect(this);">首 页</a>
                                        </li>
                                        <c:if test="${dataMap.nowPage>1}">
                                         <li class="prev"><a href="#" id="prevbt" onclick="pageSelect(this);">上一页</a>
                                         </c:if>
                                        </li>
                                        <li class="active"><span id="currentpage">${dataMap.nowPage}</span></li>
                                         <c:if test="${dataMap.nowPage<dataMap.totalPage}">
                                         <li class="next"><a href="#" id="nextbt" onclick="pageSelect(this);">下一页</a>
                                         </c:if>
                                        
                                        <li class="next"><a href="#" id="overbt" onclick="pageSelect(this);">尾 页</a>
                                    </ul>
			</c:if>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
  </form>
            </div>

            <!-- END EXAMPLE TABLE PORTLET-->

        </div>

    </div>
    <!--end tab-pane-->
</div>
<!-- BEGIN FOOTER1 -->
<%@ include file="/common/footer.jsp"%>
<!-- END FOOTER -->
<!-- BEGIN JAVASCRIPTS -->
<%@ include file="/common/js.jsp"%>
<script src="${ctx}/resource/js/app.js"></script>
<script>
    jQuery(document).ready(function () {
        App.init();
        jQuery('#promo_carousel').carousel({
            interval: 10000,
            pause: 'hover'
        });
    });
</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>